<%--
  Created by IntelliJ IDEA.
  User: JYC
  Date: 2022/4/15
  Time: 15:48:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<div class="easyui-layout" style="width:100%;height: 100%">
    <div region="north" title="搜索客户" style="height:85px;">
        <div class="easyui-panel" style="width: 100%;padding: 10px 60px" align="center">
            <input class="easyui-searchbox" data-options="prompt:'请输入出租单编号...',searcher:doSearch6" style="width:300px">
        </div>
    </div>
    <div region="west" split:true title="出租单信息" style="width:33%;" id="show11"></div>
    <div region="center" title="车辆信息" id="show12"></div>
    <div region="east" split:true title="客户信息" style="width:33%;" id="show13"></div>
    <div region="south" split:true title="检查单信息" style="height:250px;" align="center">
        <form id="chk_rr" method="post">
            <div style="margin-bottom:10px;margin-top: 10px">
                <input class="easyui-textbox" name="checkid" style="width:30%" data-options="label:'检查单号:'"
                       id="q1" readonly="readonly">

                <input class="easyui-textbox" name="datetime" style="width:30%" data-options="label:'检查日期:'"
                       id="q2" readonly="readonly">
            </div>
            <div style="margin-bottom:10px;margin-top: 10px">

                <input class="easyui-textbox" name="rentid" style="width:30%" data-options="label:'出租单号:'"
                       id="q3" readonly="readonly">
                <input class="easyui-textbox" name="opername" style="width:30%" data-options="label:'业务人员:'"
                       id="q4" readonly="readonly">
            </div>

            <div style="margin-bottom:10px">
                <input class="easyui-textbox" name="problem" style="width:30%" data-options="label:'车辆问题:'">
                <input class="easyui-textbox" name="paymoney" style="width:30%" data-options="label:'赔付金额:'">
            </div>

            <div style="margin-bottom:10px;margin-top: 10px">
                <input class="easyui-textbox" name="checkdesc" style="width:60%" data-options="label:'问题描述:'">
            </div>
            <div style="margin-bottom:10px;margin-top: 10px">
                <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok"
                   onclick="saveChk()" style="width:90px">确认</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel"
                   onclick="javascript:clearForm('chk_rr')" style="width:90px">清空</a>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    function doSearch6(val) {
        $.post('qryRents', 'rentid=' + val + '&rows=0', function (res) {
            // let res_json = JSON.parse(res);
            // console.log(res)
            if (res.total !== 0) {
                // console.log("存在！！！")
                show1(res.rows[0]);
                show2(res.rows[0].carnumber);
                show3(res.rows[0].identity);
                $.get('getChkID', function (res1) {
                    // console.log(res1);
                    $('#chk_rr').form('load', {
                        checkid: res1
                    });
                })
                $('#chk_rr').form('load', {
                    datetime: myformatter22(new Date()),
                    rentid: res.rows[0].rentid,
                    opername: res.rows[0].opername
                });
            } else {
                $.messager.show({
                    title: '提示',
                    msg: '该出租单号不存在！！！'
                })
            }
        }, 'json')
    }

    function show1(pra) {
        $("#show11").html('');
        $("#show11").append("出租单号&emsp;:&emsp;" + pra.rentid + "<br/><br/>");
        $("#show11").append("租金&emsp;:&emsp;" + pra.price + "<br/><br/>");
        $("#show11").append("起始日期&emsp;:&emsp;" + pra.begindate + "<br/><br/>");
        $("#show11").append("到期日期&emsp;:&emsp;" + pra.returndate + "<br/><br/>");
        $("#show11").append("出租状态&emsp;:&emsp;" + (pra.rentflag == 0 ? '出租中' : '已归还') + "<br/><br/>");
        $("#show11").append("客户编号&emsp;:&emsp;" + pra.identity + "<br/><br/>");
        $("#show11").append("车牌号码&emsp;:&emsp;" + pra.carnumber + "<br/><br/>");
        $("#show11").append("业务经理&emsp;:&emsp;" + pra.opername + "<br/><br/>");
    }

    function show2(pra) {
        $("#show12").html('');
        $.get('qryCar', 'carnumber=' + pra + '&rows=0', function (res) {
            res = JSON.parse(res);
            if (res.rows.length === 1) {
                var car = res.rows[0];
                $("#show12").append("车辆号牌&nbsp;:&nbsp;" + car.carnumber + "<br/><br/>");
                $("#show12").append("车辆类型&nbsp;:&nbsp;" + car.cartype + "<br/><br/>");
                $("#show12").append("车辆颜色&nbsp;:&nbsp;" + car.color + "<br/><br/>");
                $("#show12").append("车辆价格&nbsp;:&nbsp;" + car.price + "<br/><br/>");
                $("#show12").append("车辆租金&nbsp;:&nbsp;" + car.rentprice + "<br/><br/>");
                $("#show12").append("车辆押金&nbsp;:&nbsp;" + car.deposit + "<br/><br/>");
                $("#show12").append("车辆状态&nbsp;:&nbsp;" + (car.isrenting == 0 ? '未出租' : '已出租') + "<br/><br/>");
                $("#show12").append("车辆描述&nbsp;:&nbsp;" + car.description + "<br/><br/>");
                $("#show12").append("车辆图片&nbsp;:&nbsp;<img src='" +
                    car.carimg + "' width='200px'/><br/><br/>");
            }
        })
    }

    function show3(pra) {
        $("#show13").html('');
        $.post("getCust", "identity=" + pra + "&rows=0", function (result) {
            result = JSON.parse(result);
            var cust = result.rows[0];
            $("#show13").append("客户编号&nbsp;:&nbsp;" + cust.identity + "<br/><br/>");
            $("#show13").append("客户姓名&nbsp;:&nbsp;" + cust.custname + "<br/><br/>");
            $("#show13").append("客户性别&nbsp;:&nbsp;" + (cust.sex == 1 ? '男' : '女') + "<br/><br/>");
            $("#show13").append("客户地址&nbsp;:&nbsp;" + cust.address + "<br/><br/>");
            $("#show13").append("客户电话&nbsp;:&nbsp;" + cust.phone + "<br/><br/>");
            $("#show13").append("客户职业&nbsp;:&nbsp;" + cust.career + "<br/><br/>");
        });
    }

    function saveChk() {
        let formdata = $('#chk_rr').serializeJson();
        // console.log(formdata)
        $.post('addChk', formdata, function (res) {
            if (res.ok) {
                $.messager.alert('提示', res.ok, 'info');
            } else {
                $.messager.alert('提示', res.errorMsg, 'error');
            }
        })
    }

    function myformatter22(value) {
        var date = new Date(value);
        var year = date.getFullYear().toString();
        var month = (date.getMonth() + 1);
        var day = date.getDate().toString();
        var hour = date.getHours().toString();
        var minutes = date.getMinutes().toString();
        var seconds = date.getSeconds().toString();
        if (month < 10) {
            month = "0" + month;
        }
        if (day < 10) {
            day = "0" + day;
        }
        if (hour < 10) {
            hour = "0" + hour;
        }
        if (minutes < 10) {
            minutes = "0" + minutes;
        }
        if (seconds < 10) {
            seconds = "0" + seconds;
        }
        return year + "-" + month + "-" + day + " " + hour + ":" + minutes + ":" + seconds;
    }
</script>
</body>
</html>
